import { IStageAssetsInfo } from "babylon-lib/base/stage";
import { XRStage } from 'babylon-lib/base/xr-stage';
import { Scene } from "@babylonjs/core/scene";
import { Camera } from "@babylonjs/core/Cameras/camera";
import { Light } from "@babylonjs/core/Lights/light";
import { RawAssetsUrl } from "../raw-assets-info";
import { GenerateComponent } from './default-stage-components/generate-component';
import { ILoose } from "babylon-lib/tool/utils";
import { AbstractAssetTaskInfo, CubeTextureTaskInfo, GLTFMeshTaskInfo } from "babylon-lib/loader/asset-task-info";
import * as Data from '../data/data';
import { IActiveDefaultVRExperienceOptions } from 'babylon-lib/xr/vr-container';
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { SEPARATE_NO_ROTATE_HANDEDNESS_CONFIGURATION } from "babylon-lib/xr/vr-motion/vr-motion-movement";
import { IActiveDefaultARExperienceOptions } from "babylon-lib/xr/ar-container";
import { WebXRDefaultExperience } from "@babylonjs/core/XR/webXRDefaultExperience";


class DefaultStage extends XRStage {

    protected appName(): string {
        return 'default';
    }

    protected isProduction(): boolean {
        return false;
    }

    protected assetTaskInfos(): ILoose<AbstractAssetTaskInfo> | Array<IStageAssetsInfo> {
        return {
            changjing: new GLTFMeshTaskInfo(RawAssetsUrl.changjing),

            lightCube: new CubeTextureTaskInfo(
                this.bufferLoader.getInfo(RawAssetsUrl.lightCubePX)!,
                RawAssetsUrl.lightCubePY,
                this.bufferLoader.getInfo(RawAssetsUrl.lightCubePZ)!,
                RawAssetsUrl.lightCubeNX,
                '../asset/texture/lightCube/pz.png',
                '../asset/texture/lightCube/nz.png'
            ),

        };
    }

    protected getXROptions(): IActiveDefaultVRExperienceOptions | IActiveDefaultARExperienceOptions {
        return {
            // useDefaultEnterExitUi: true,
            renderingGroupId: 3,
            cameraOptions: {
                position: Data.cameraPosition.value,
                target: Data.cameraTarget.value,
                maxZ: 1000,
                checkCollisions: true,
                applyGravity: true,
                ellipsoid: new Vector3(0.5, 1.6, 0.5),
                ellipsoidOffset: new Vector3(0, 1.6, 0),
                speed: 0.15,
            },
            enableMovement: true,
            movementOptions: {
                customRegistrationConfigurations: SEPARATE_NO_ROTATE_HANDEDNESS_CONFIGURATION,
            },
            disableTeleportation: true,
            // teleportationOptions: {
            //     floorMeshes: floors,
            // },
        };
    }

    protected generateComponents(scenes: Scene[], cameras: Camera[], lights: Light[]): void {
        GenerateComponent.initialize(this);
        this.bindData();
    }

    public onWindowResize(rect: DOMRect): void {
        Data.test.detailView.windowResizeUpdate();
    }

    private bindData(): void {
    }

}


export { DefaultStage };